/*******************************************************************************
* CHIPSEA F60 TEMPSENSOR HAL
*******************************************************************************/

#include "hal_cs_f60_tempsensor.h"

#ifdef CS_F60

#include <stdint.h>


/* TODO
 * The function of temsensor is not finishing
 */
unsigned short TempSensorFactorADC = 28500;

void HAL_TempSensor_Init(void)
{
	System_TempSensorInit(HCLK_Div_2 , ENABLE);
}

/*****************************************************************************
@brief  温度传感器参数初始化
@param  None
@retval None
******************************************************************************/
void Temp_FactorInit(void)
{
	uint8_t dat[4];
	uint8_t temp;

	FMC_ReadPage (0x100F00, 4, dat); //读温度校准数据

	temp = dat[0]+dat[1];

	if(temp == dat[2]) //校验测试
	{
		TempSensorFactorADC = dat[1];
		TempSensorFactorADC <<= 8;
		TempSensorFactorADC |= dat[0];
	}
}

uint16_t hal_temperature_read(void)
{
	uint16_t tempSensorADC;

	System_TempSensorStartChange();

	while(System_TempSensorBusy()) {}

	tempSensorADC = System_ReadTempSensorData();

	return tempSensorADC;
}

#endif /* End of CS_F60 */
